import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;
import net.sourceforge.tess4j.util.ImageHelper;
import org.junit.Test;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created by ChoviWu on 2018/04/18
 * Description:
 */
//@RunWith(SpringRunner.class)
//@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class Test1 {





    @Test
    public void test2() throws TesseractException {
        File imageFile = null;
        try {
            imageFile = new File("E:/1525584760367.jpg");
//            String url = ImageOCR.getAllOcr("E:/1525584760367.jpg");
//            System.out.println(url);
//            imageFile = new File("E:/0056.png");
        } catch (Exception e) {
            e.printStackTrace();
        }
        Tesseract instance = new Tesseract();
        String path = "E:\\tool\\example\\example-test\\tessdata";
        //如果需要识别英文之外的语种，需要指定识别语种，并且需要将对应的语言包放进项目中
        instance.setLanguage("eng");
        instance.setDatapath(path);
        //将验证码图片的内容识别为字符串
//        String result = instance.doOCR(test.Test.dealImage(imageFile,""));
//        System.out.println("结果是： "+result);
    }

    public static BufferedImage change(File file){

        // 读取图片字节数组
         BufferedImage textImage = null;
         try {
                 InputStream in = new FileInputStream(file);
                 BufferedImage image = ImageIO.read(in);
                   textImage = ImageHelper.convertImageToGrayscale(ImageHelper.getSubImage(image, 0, 0, image.getWidth(), image.getHeight()));  //对图片进行处理
                  textImage = ImageHelper.getScaledInstance(image, image.getWidth() * 5, image.getHeight() * 5);  //将图片扩大5倍

                 } catch (IOException e) {
                    e.printStackTrace();
                }

           return textImage;
    }

}
